import Vue from 'vue'
import Vuex from 'vuex'
import {get_photo} from '../../API/high_plus.js'


Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		gallery_arr: [],
		gallery_shownums:0,
		items_x: [],
		shownpics: 0,
		search_result:[],
	},
	mutations: {
		change_gallery_arr(state, arr) {
			state.gallery_arr = arr;
		},
		change_shownpics(state) {
			state.shownpics += 20;
		},
		change_items_x(state,temp){
			state.items_x = temp;
		},
		change_search_result(state, arr){
			state.search_result = arr;
		}
	},
	actions: {
		get_photo_vux(context, obj){
			get_photo(obj).then(res => {
				// console.log(res.data.data.photo_list);
				context.commit("change_gallery_arr", res.data.data.photo_list);
				console.log(context.state.gallery_arr);
			})
		},
		slice_gallery_item(context){
			context.commit("change_shownpics");
			
			let temp = context.state.gallery_arr.slice(0, context.state.shownpics);
			let temp2 = [];
			temp.forEach(el => {
				temp2.push({
					id: el.photo_id,
					src: el.thumb_w_url_cos,
					loading: true,
					error: false,
					ratio: el.origin_w / el.origin_h,
				})
			})
			context.commit("change_items_x",temp2);
		}
	},
	modules: {}
})
